package cn.edu.cug.cs.gtl.renders.openinventor.paths;

import cn.edu.cug.cs.gtl.apis.render.nodes.Node;
import cn.edu.cug.cs.gtl.apis.render.paths.GeneralPath;
import cn.edu.cug.cs.gtl.apis.render.paths.Path;
import cn.edu.cug.cs.gtl.renders.openinventor.nodes.NodeImpl;
import com.openinventor.inventor.SoGeneralPath;
import com.openinventor.inventor.SoPath;
import com.openinventor.inventor.nodes.SoNode;

public class GeneralPathImpl implements GeneralPath {
    private SoGeneralPath nativeObject=null;

    public GeneralPathImpl(SoGeneralPath nativeObject) {
        this.nativeObject = nativeObject;
    }

    @Override
    public Object getNativeObject() {
        return nativeObject;
    }

    @Override
    public boolean attach(Object nativeObject) {
        if(nativeObject instanceof SoGeneralPath) {
            this.nativeObject = (SoGeneralPath) nativeObject;
            return true;
        }
        return false;
    }

    @Override
    public Object detach() {
        SoGeneralPath p = this.nativeObject;
        this.nativeObject=null;
        return p;
    }

    @Override
    public void append(int childIndex) {
        this.nativeObject.append(childIndex);
    }

    @Override
    public void append(Node childNode) {
        this.nativeObject.append((SoNode) childNode.getNativeObject());
    }

    @Override
    public void append(Path fromPath) {
        this.nativeObject.append((SoPath) fromPath.getNativeObject());
    }

    @Override
    public boolean containsNode(Class type) {
        return this.nativeObject.containsNode(type);
    }

    @Override
    public boolean containsNode(Node node) {
        return this.nativeObject.containsNode((SoNode) node.getNativeObject());
    }

    @Override
    public boolean containsPath(Path path) {
        return this.nativeObject.containsPath((SoPath) path.getNativeObject());
    }

    @Override
    public Path copy(int startFromNodeIndex) {
        SoPath p =  this.nativeObject.copy(startFromNodeIndex);
        return new PathImpl(p);
    }

    @Override
    public Path copy(int startFromNodeIndex, int numNodes) {
        SoPath p =  this.nativeObject.copy(startFromNodeIndex,numNodes);
        return new PathImpl(p);
    }

    @Override
    public int findFork(Path path) {
        return this.nativeObject.findFork((SoPath) path.getNativeObject());
    }

    @Override
    public Node getHead() {
        return new NodeImpl(this.nativeObject.getHead());
    }

    @Override
    public int getIndex(Class type) {
        return this.nativeObject.getIndex(type);
    }

    @Override
    public int getIndex(int i) {
        return this.nativeObject.getIndex(i);
    }

    @Override
    public int getIndexFromTail(int i) {
        return this.nativeObject.getIndexFromTail(i);
    }

    @Override
    public int getInstanceIndex(int i) {
        return this.nativeObject.getInstanceIndex(i);
    }

    @Override
    public int getInstanceIndexFromTail(int i) {
        return this.nativeObject.getInstanceIndexFromTail(i);
    }

    @Override
    public int getLength() {
        return this.nativeObject.getLength();
    }

    @Override
    public Node getNode(Class type) {
        return new NodeImpl(this.nativeObject.getNode(type));
    }

    @Override
    public Node getNode(int i) {
        return new NodeImpl(this.nativeObject.getNode(i));
    }

    @Override
    public Node getNodeFromTail(int i) {
        return new NodeImpl(this.nativeObject.getNodeFromTail(i));
    }

    @Override
    public Node getTail() {
        return new NodeImpl(this.nativeObject.getTail());
    }

    @Override
    public void pop() {
        this.nativeObject.pop();
    }

    @Override
    public void push(int childIndex) {
        this.nativeObject.push(childIndex);
    }

    @Override
    public void setHead(Node node) {
        this.nativeObject.setHead((SoNode) node.getNativeObject());
    }

    @Override
    public void truncate(int start) {
        this.nativeObject.truncate(start);
    }
}
